extends Control

signal mouse_on_panel
signal select_unit
signal play

var player_deck : Deck
var button_group := ButtonGroup.new()

func _ready():
	player_deck = Globals.get_user_deck()
	reload_deck_buttons()

func reload_deck_buttons():
	var ubc = $"%UnitButtonsContainer"
	for unit in player_deck.chosen_units:
		var ub = UnitButton.new()
		ub.text = unit
		ub.toggle_mode = true
		ub.group = button_group
		ub.size_flags_horizontal = SIZE_FILL
		ub.size_flags_vertical = SIZE_FILL
		ub.align = Button.ALIGN_CENTER
		ub.mouse_filter = Control.MOUSE_FILTER_PASS
		ub.unit = ub.get_unit_from_name(unit)
		ub.icon = ub.unit.get_sprite()
		ub.expand_icon = true
		ub.connect("selected", self, "_on_ub_selected")
		ubc.add_child(ub)


func _on_Panel_mouse_entered():
	emit_signal("mouse_on_panel", true)


func _on_Panel_mouse_exited():
	emit_signal("mouse_on_panel", false)
	
func _on_ub_selected(unit):
	emit_signal("select_unit", unit)


func _on_PlayButton_pressed():
	emit_signal("play")
